// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Jamie Nicolson
//
// Protocol class.

#ifndef POPDIAG_UTIL_PROTOCOL_H__
#define POPDIAG_UTIL_PROTOCOL_H__

#include "util/common.h"

namespace popdiag {

// Provides constant information about the protocols we use.
class Protocol {
 public:
  // Returns true if the given hostname is a server of this protocol.
  virtual bool IsOurMailServer(const QString &hostname) const = 0;

  // The SSL port for this protocol.
  virtual int SecurePort() const = 0;

  // Returns true if we allow plaintext access to this protocol.
  virtual bool HasPlaintextPort() const = 0;

  // The plaintext port for this protocol.
  virtual int PlaintextPort() const = 0;

  // Whether SPA may be used for authentication.
  virtual bool MustNotUseSpa() const = 0;

  // Returns true if the username and the email address match (to
  // whatever provider-specific extent required), or if it is okay
  // for them to differ.
  virtual bool VerifyUsernameFromEmailAddress(const QString &username,
                                              const QString &email) const = 0;

  // A displayable name for this protocol.
  QString Name() const;

  // Protocol singletons.
  static const Protocol& POP();
  static const Protocol& IMAP();
  static const Protocol& SMTP();

  virtual ~Protocol();

 protected:
  Protocol(const QString& protocol_name);

 private:
  QString protocol_name_;

  DISALLOW_EVIL_CONSTRUCTORS(Protocol);
};
}

#endif  // POPDIAG_UTIL_PROTOCOL_H__
